﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Sale_Common;
using Sale_Model;
using Sale_DAL;
namespace Sale_Operation
{
    public class LinkService
    {
        
        public static int PageSize
        {
            get
            {
                if (System.Web.HttpContext.Current.Application["PageSize"] == null)
                {
                    SysConfigOp Manager = new SysConfigOp();
                    SysConfig SM = new SysConfig();
                    SM.SConf_Id = 3;
                    Manager.GetConfig(SM);
                    System.Web.HttpContext.Current.Application["PageSize"] = SM.SConf_Value;
                }
                return int.Parse(System.Web.HttpContext.Current.Application["PageSize"].ToString());
            }
            set
            {
                System.Web.HttpContext.Current.Application["PageSize"] = value; 
            }
        }
        public static HttpSession Session()
        {
            HttpSession session = new HttpSession();
            return session;
        }
        public static SysUser GetCurrentUser()
        {
            HttpSession session = new HttpSession();
            if (session["CurrentUser"] != null)
                return (SysUser)session["CurrentUser"];
            else
            {
                System.Web.HttpContext.Current.Response.Redirect("index.aspx");
                return null;
            }
        }
        public static void InsertLog(ESysLogType eNum, string SLog_Content,EMenuList emenu)
        {
            SystemLogOp.Add(eNum, SLog_Content, (int)emenu);
        }
        /// <summary>
        /// 检测要删除的记录是否正在被使用
        /// </summary>
        /// <param name="Table_Name">要删除记录的表名</param>
        /// <param name="Rela_Value">要删除的关联字段的值</param>
        /// <returns>bool</returns>
        public static bool CheckIsUsing(string Table_Name, string Rela_Value)
        {
            bool Res = false;
            DataBase db = new DataBase();
            try
            {
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append("SP_CheckDelete '" + ValueHandler.GetStringValue(Table_Name, ValueHandler.CharHandlerType.IsDelChar) + "','" + ValueHandler.GetStringValue(Rela_Value, ValueHandler.CharHandlerType.IsDelChar) + "',''");
                SqlHelper.FillDataset(db.Connection, CommandType.Text, sbSql.ToString(), db.Data, new string[] { "Res" });
                if (db.Data.Tables[0] != null && db.Data.Tables[0].Rows.Count > 0)
                    Res = true;
            }
            catch (Exception ex)
            {
            
                SystemLogOp.Add(ESysLogType.Error, ex.ToString().ToString(), 0);
            }
            db.Close();
            return Res;
        }
        public static string RefreshString = "refreshParent";
        public static string RefreshTag = "__EVENTARGUMENT";
        public static DataTable GetPayType()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Id");
            dt.Columns.Add("Name");
            DataRow dr = dt.NewRow();
            dr[0] = "1";
            dr[1] = "现金";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr[0] = "2";
            dr[1] = "刷卡";
            dt.Rows.Add(dr);
            return dt;
        }
        public static DataTable GetSBill_State()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Id");
            dt.Columns.Add("Name");
            DataRow dr = dt.NewRow();
            dr[0] = "0";
            dr[1] = "未结算";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr[0] = "1";
            dr[1] = "已结算";
            dt.Rows.Add(dr);
            return dt;
        }
        public static DataTable GetAnalyzeType()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Id");
            dt.Columns.Add("Name");
            DataRow dr = dt.NewRow();
            dr["Id"] = 1;
            dr["Name"] = "年度";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["Id"] = 2;
            dr["Name"] = "月度";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["Id"] = 3;
            dr["Name"] = "天";
            dt.Rows.Add(dr);
            return dt;
        }
    }
}
